import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('cart', () => {
 
    let piniacart=ref([]);
    let piniaus=(xq,goods_id)=>{
        let username=localStorage.getItem('username');
        let pd=piniacart.value.find(item=>item.goods.goods_id==goods_id)
        if(pd){
            pd.number++
        }
        else{
            piniacart.value.push({
                number:1,
                username:username,
                cheched:false,
                goods:xq,
                id:Math.floor(Math.random()*100000)
            })
        }
    }

  return {piniacart,piniaus  }
},
 {
    persist: true,
  },
)
